package culaocham.sinhvat.action;

import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.bean.DongVatModel;
import model.bean.ThucVatModel;
import model.bo.ProcessBO;

import org.apache.catalina.connector.Request;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import culaocham.sinhvat.form.UserForm;

public class LoginAction extends Action{
	String user;
	String password;

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		UserForm userForm = (UserForm) form;
		user = userForm.getUser();
		password = userForm.getPassword();
		
		ProcessBO proessBO = new ProcessBO();
		
		if(proessBO.checkLogin(user, password)){
			
			// Set list dong vat vao formbean 
			ArrayList<DongVatModel> listDongVatModel = proessBO.listInfoDongVat();
			userForm.setListDongVatModel(listDongVatModel);
			
			// Set list thuc vat vao formbean
			ArrayList<ThucVatModel> listThucVatModel = proessBO.listInfoThucVat();
			userForm.setListThucVatModel(listThucVatModel);
			
			return mapping.findForward("user");
			
		} else {
			request.setAttribute("loi", "saidangnhap");
			return mapping.findForward("login");
		}
	}
}